\doxysection{x\+Semaphore\+Give\+Recursive }
\hypertarget{group__x_semaphore_give_recursive}{}\label{group__x_semaphore_give_recursive}\index{xSemaphoreGiveRecursive@{xSemaphoreGiveRecursive}}
semphr. h 
\begin{DoxyPre}xSemaphoreGiveRecursive( SemaphoreHandle\_t xMutex )\end{DoxyPre}


{\itshape Macro} to recursively release, or \textquotesingle{}give\textquotesingle{}, a mutex type semaphore. The mutex must have previously been created using a call to x\+Semaphore\+Create\+Recursive\+Mutex();

config\+USE\+\_\+\+RECURSIVE\+\_\+\+MUTEXES must be set to 1 in \doxylink{_free_r_t_o_s_config_8h_source}{Free\+RTOSConfig.\+h} for this macro to be available.

This macro must not be used on mutexes created using x\+Semaphore\+Create\+Mutex().

A mutex used recursively can be \textquotesingle{}taken\textquotesingle{} repeatedly by the owner. The mutex doesn\textquotesingle{}t become available again until the owner has called x\+Semaphore\+Give\+Recursive() for each successful \textquotesingle{}take\textquotesingle{} request. For example, if a task successfully \textquotesingle{}takes\textquotesingle{} the same mutex 5 times then the mutex will not be available to any other task until it has also \textquotesingle{}given\textquotesingle{} the mutex back exactly five times.


\begin{DoxyParams}{Parameters}
{\em x\+Mutex} & A handle to the mutex being released, or \textquotesingle{}given\textquotesingle{}. This is the handle returned by x\+Semaphore\+Create\+Mutex();\\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
pd\+TRUE if the semaphore was given.
\end{DoxyReturn}
Example usage\+: 
\begin{DoxyPre}
SemaphoreHandle\_t xMutex = NULL;

// A task that creates a mutex.
void vATask( void * pvParameters )
\{
   // Create the mutex to guard a shared resource.
   xMutex = xSemaphoreCreateRecursiveMutex();
\}

// A task that uses the mutex.
void vAnotherTask( void * pvParameters )
\{
   // ... Do other things.

   if( xMutex != NULL )
   \{
       // See if we can obtain the mutex.  If the mutex is not available
       // wait 10 ticks to see if it becomes free.
       if( xSemaphoreTakeRecursive( xMutex, ( TickType\_t ) 10 ) == pdTRUE )
       \{
           // We were able to obtain the mutex and can now access the
           // shared resource.

           // ...
           // For some reason due to the nature of the code further calls to
        // xSemaphoreTakeRecursive() are made on the same mutex.  In real
        // code these would not be just sequential calls as this would make
        // no sense.  Instead the calls are likely to be buried inside
        // a more complex call structure.
           xSemaphoreTakeRecursive( xMutex, ( TickType\_t ) 10 );
           xSemaphoreTakeRecursive( xMutex, ( TickType\_t ) 10 );

           // The mutex has now been 'taken' three times, so will not be
        // available to another task until it has also been given back
        // three times.  Again it is unlikely that real code would have
        // these calls sequentially, it would be more likely that the calls
        // to xSemaphoreGiveRecursive() would be called as a call stack
        // unwound.  This is just for demonstrative purposes.
           xSemaphoreGiveRecursive( xMutex );
        xSemaphoreGiveRecursive( xMutex );
        xSemaphoreGiveRecursive( xMutex );

        // Now the mutex can be taken by other tasks.
       \}
       else
       \{
           // We could not obtain the mutex and can therefore not access
           // the shared resource safely.
       \}
   \}
\}
\end{DoxyPre}
 